package test;



import com.sleepycat.db.DatabaseException;


import fr.cephb.joperon.core.Operon;
import fr.cephb.joperon.core.db.SnpIdsDB;
import fr.cephb.joperon.core.entities.SnpIds;
import fr.cephb.joperon.tool.OperonFactory;
import fr.cephb.lang.Endian;
import fr.cephb.util.Pair;

/*
 
same example as Example030
but using the listing the key and the values

 */
public class Example040
	{
	public static void main(String[] args)
		{
		Endian.setDefault(Endian.CNG);
		Operon operon=null;
		OperonFactory factory = null;
		SnpIdsDB.KeyValueIterator iter=null;
		try {
			operon= Operon.newInstance();
			//open a factory  with the default assembly
			factory= new OperonFactory(operon);
			
			
			if(!factory.isSnpIdsExists())
				{
				throw new DatabaseException("no database for this assembly "+factory.getAssembly());
				}
			
			//loop over all values
			iter=factory.getSnpIds().listKeyValues();
			
			while(iter.hasNext())
				{
				Pair<String,SnpIds> str_snpid= iter.next();
				System.out.println(
						str_snpid.first()+"\t"+
						str_snpid.second().getChromosome()+"\t"+
						str_snpid.second().getPosition()
						);
				}
			
			} 
		catch (Exception e) {
			//print error if any
			e.printStackTrace();
			}
		finally
			{
			//ALWAYS close the iterator
			if(iter!=null) iter.close();
			//ALWAYS close the factory
			if(factory!=null) factory.close();
			//ALWAYS close operon
			if(operon!=null) operon.safeClose();
			}
		}
	}
